package com.glela.order.dao;

import java.util.Collection;
import java.util.List;
import java.util.Set;

import com.glela.goods.model.GoodsCommission;
import com.glela.goods.model.LimitTimeSaleGoodsCommission;
import com.glela.goods.model.ShareGoods;
import com.glela.goods.model.TalentSerialGood;
import com.glela.goods.model.vo.InventoryVo;
import com.glela.order.model.Commision;
import com.glela.order.model.OrderDetail;
import com.glela.order.model.OrderInfo;
import com.glela.order.model.OrderObject;
import com.glela.order.model.OrderSettlement;
import com.glela.order.model.OrderStatus;
import com.glela.order.model.PayTypeConfig;
import com.glela.order.model.PayTypeList;
import com.glela.order.vo.OrderDetailVo;
import com.glela.order.vo.OrderInfoVo;
import com.glela.order.vo.OrderSettlementVo;
import com.glela.platform.model.response.ResponseUser;
import com.glela.platform.vo.GoodsSimpleVo;

/**
 *@author liujie
 *@2016年10月25日
 */
public interface OrderDao {

	public OrderDetail selectByUserGoodApplywelfareId(long userId, long goodId,
			int applywelfareId,int activityType);
	
	/**
	 * 根据商品库存id查询商品信息
	 * @param goods
	 * @return List<GoodsSimpleVo>
	 */
	public List<GoodsSimpleVo> selectGetOrderGoodsInfo(List<GoodsSimpleVo> goods);

	/**
	 * <dl>
	 * <dt>更具库存id查询商品信息</dt>
	 * </dl>
	 * @param inventoryIds 库存集合
	 * @return List<GoodsSimpleVo>
	 * @author zls
	 * @date 2017年12月8日 下午5:10:01
	 */
	List<GoodsSimpleVo> selectGetOrderGoodsInfo(Collection<Long> inventoryIds);
	/**
	 * <dl>
	 * <dt>查询开店单</dt>
	 * </dl>
	 * @param buyUserId 购买人
	 * @return List<OrderObject>
	 * @author zls
	 * @date 2017年8月23日 下午6:58:48
	 */
	public List<OrderObject> selectOpenOrder(Long buyUserId);

	/**
	 * 扣减库存
	 * @param inventoryId 库存id
	 * @param quantity 扣减数量（无符号）
	 * @return int 更改记录数
	 * @author zls
	 */
	public int subInventoryNumById(long inventoryId, int quantity);
	
	public int batchSubInventoryNumById(List<OrderDetail> orderDetailList);
	
	public List<InventoryVo> selectInventoryInId(Set<Long> inventoryIdSet);
	
	public int insertSelective(OrderObject orderObject);
	
	public int insertOrderObjectSelective(OrderObject record);
	
	public OrderObject selectOrderObjectByPrimaryKey(long id);
	
	public OrderObject selectOrderObjectByOrderSn(String orderSn);
	
	public int batchInsertOrderInfo(List<OrderInfo> list);
	
	public int batchInsertOrderDetail(List<OrderDetail> list);
	
	public int insertOrderInfoSelective(OrderInfo orderInfo);
	
	public List<TalentSerialGood> selectTalentSerialGoodInId(List<GoodsSimpleVo> list);
	
	public List<ShareGoods> selectShareGoodsInId(List<GoodsSimpleVo> list);
	
	public List<OrderDetail> selectOrderDetilByOrderObjectId(Long orderObjectId);
	
	/**
	 * 商品分佣信息集合
	 * @param inOrderDetailList 根据goodId获取商品分佣信息
	 * @return List<GoodsCommission>
	 * @author zls
	 */
	public List<GoodsCommission> selectGoodsCommissionListInGoodId(List<OrderDetail> inOrderDetailList);

	/**
	 * 分时抢购商品分佣信息集合
	 * @param inOrderDetailList 根据分时抢购ID获取商品分佣信息
	 * @return List<LimitTimeSaleGoodsCommission>
	 * @author gwq
	 */
	public List<LimitTimeSaleGoodsCommission> selectLimitTimeSaleGoodsCommissionListInGoodId(List<OrderDetail> inOrderDetailList);
	/**
	 * 获取用户角色信息集合
	 * <dd>用户推荐人身份为普通人、会员、达人或者用户id为商品分享者id</dd>
	 * <dd>不包含用户详细信息</dd>
	 * @param orderDetailList item.talentId 商品分享达人id
	 * @param user 当前用户
	 * @return List<ResponseUser>
	 * @author zls
	 */
	public List<ResponseUser> selectTalentIdAndUserReRoleInId(List<OrderDetail> orderDetailList, ResponseUser user);

	/**
	 * <dl>
	 * <dt>获取用户及角色信息集合</dt>
	 * <dd>根据用户身份id</dd>
	 * </dl>
	 * @param personIdlist 用户身份id集合
	 * @return List<ResponseUser>
	 * @author zls
	 */
	public List<ResponseUser> selectUserRoleInPersonId(List<String> personIdlist);
	
	public int batchInsertCommision(List<Commision> list);
	
	public int batchInsertOrderSettlement(List<OrderSettlement> list);
	
	public int updateOrderObjectByPrimaryKeySelective(OrderObject record);
	
	public int batchUpdateCommisionFeeAndPointFeeById(List<OrderInfo> list);
	
	
	/**
	 * <dl>
	 * <dt>获取可分佣交易单</dt>
	 * </dl>
	 * @return List<OrderObject>
	 * @author zls
	 */
	public List<OrderObject> selectOrderObjectForCommision();
	
	public List<Commision> selectByOrderObjectIdForCommision(long orderOBJid);
	
	/**
	 * <dl>
	 * <dt>查询未处理分佣信息(仅查找账务类型是 1 2 3 17 {开店 直接 间接分佣 角色级别分佣})</dt>
	 * </dl>
	 * @param orderObjectList
	 * @return List<Commision>
	 * @author gaoweiqi
	 */
	public List<Commision> selectInOrderObjectIdForCommision(List<OrderObject> orderObjectList);

	/**
	 * <dl>
	 * <dt>获取可分佣订单</dt>
	 * </dl>
	 * @param orderObjectList item.id 交易单id
	 * @return List<OrderInfo>
	 * @author zls
	 */
	public List<OrderInfo> selectOrderInfoInOOIdForCommision(List<OrderObject> orderObjectList);
	
	/**
	 * <dl>
	 * <dt>更新分佣明细为已处理</dt>
	 * </dl>
	 * @param commisionList item.id 分佣明细id
	 * @return int
	 * @author zls
	 */
	public int updateCommisionResultInId(List<Commision> commisionList,String resultTime);
	
	/**
	 * <dl>
	 * <dt>更新订单明细状态为交易成功</dt>
	 * </dl>
	 * @param orderObjectList item.id 交易单id
	 * @return int
	 * @author zls
	 */
	public int updateOrderDetailStatusInOrderObjectId(List<OrderObject> orderObjectList);
	
	/**
	 * <dl>
	 * <dt>更新订单状态为交易已成功</dt>
	 * </dl>
	 * @param orderObjectList item.id 交易单id
	 * @return int
	 * @author zls
	 */
	public int updateOrderInfoStatusInOrderObjectId(List<OrderObject> orderObjectList);
	
	/**
	 * <dl>
	 * <dt>更新交易单状态为交易成功</dt>
	 * </dl>
	 * @param orderObjectList item.id 交易单id
	 * @return int
	 * @author zls
	 */
	public int updateOrderObjectStatusInId(List<OrderObject> orderObjectList);
	
	/**
	 * <dl>
	 * <dt>更新交易单信息</dt>
	 * <dd>状态改为待发货</dd>
	 * </dl>
	 * @param id 交易单id
	 * @param bankIn 银行实收
	 * @param procedureFee 手续费
	 * @param payType 支付方式
	 * @param paymentFee 实际支付金额
	 * @param payId 第三方交易流水号
	 * @param payTime 支付时间
	 * @return int 更新交易单条数
	 * @author zls
	 */
	public int updateOrderObjectPay(long id, long bankIn, long procedureFee, int payType, long paymentFee, String payId, String payTime);

	/**
	 * <dl>
	 * <dt>更新订单支付信息</dt>
	 * <dd>状态改为待发货</dd>
	 * </dl>
	 * @param orderObjectId 交易单id
	 * @param bankIn 银行实收
	 * @param procedureFee 手续费
	 * @param payType 支付方式
	 * @param paymentFee 实际支付金额
	 * @param payId 第三方交易流水号
	 * @param payTime TODO
	 * @return int 更新订单条数
	 * @author zls
	 */
	public int updateOrderInfoPayByOrderObjectId(long orderObjectId, int bankIn, int procedureFee, int payType, int paymentFee, String payId, String payTime);
	
	public OrderInfo selectOrderInfoEntityByOrderSn(String orderSn);
	
	/**
	 * <dl>
	 * <dt>获取订单列表</dt>
	 * <dd>订单状态不能为取消（5）</dd>
	 * </dl>
	 * @param orderSn 交易单号
	 * @param status 订单状态 不包含5
	 * @return List<OrderInfoVo>
	 * @author zls
	 */
	public List<OrderInfoVo> selectOrderInfoVoByStatusOrderObjectSn(String orderSn,Integer status);
	
	/**
	 * <dl>
	 * <dt>获取订单明细列表</dt>
	 * <dd>订单状态不能为取消（5）</dd>
	 * </dl>
	 * @param orderSn 交易单号
	 * @param status 订单明细状态 不包含5
	 * @return List<OrderDetailVo>
	 * @author zls
	 */
	public List<OrderDetailVo> selectOrderDetailByStatusOrderObjectSn(String orderSn,Integer status);
	
	/**
	 * <dl>
	 * <dt>更新订单商品明细状态</dt>
	 * <dd>根据交易单号id</dd>
	 * <dd>状态改为待发货</dd>
	 * </dl>
	 * @param orderObjectId 交易单id
	 * @return int 影响行数
	 * @author zls
	 */
	public int updateOrderDetailPayByOrderObjectId(long orderObjectId);
	
	/**
	 * 查询支付类型配置
	 * @param status 状态：0禁用；1启用
	 * @return List<PayTypeConfig>
	 */
	public List<PayTypeConfig> selectPayTypeConfigByStatus(Integer status);

	/** 获取支付类型配置 */
	List<PayTypeList> selectPayTypeList(PayTypeList queryPayTypeList);
	
	public int updateSettlementStatusByID(Long ID,int status,String settlementNo,String companyAccount,String managerAccount,int selfSupport);
	
	public int updateSettlementStatusByOrderSn(String orderSn,int status,String settlementNo);
	
	public List<OrderSettlementVo> selectByOrderSnForSettlement(String orderSn);
	
	public List<OrderSettlementVo> selectByOrderSnForFreightSettlement(String orderSn);
	
	public int updateOrderObjectPayUrlById(long id,String payUrl);

	public int updateOrderObjectFreightNo(Long orderObjectId, String refundFeeNo);
	
	public List<OrderSettlementVo> selectByOrderSnForSettlementDetail(String orderSn);

	public int selectDetailGoodsType(Long orderObjectId);

	public String selectSettlementAccount(Long orderObjectId);
	
	public int updateHandlestatusByOrderSn(String orderSn);

	public List<OrderStatus> selectForStatusUserOrderObjectSn(String orderObjectSn);

	public int updateOrderDetailStatusByOrderInfoId(long orderInfoId,int nextStatus, int limitStatus);

	public int updateOrderInfoStatusById(long orderInfoId,int nextStatus, int limitStatus);

	public int updateOrderObjectStatusById(long orderObjectId,int nextStatus, int limitStatus);

	public String selectOrderObjectSnByOrderInfoSn(String orderInfoSn);

	public int updateOrderDetailStatusById(long orderObjectId,int nextStatus, int limitStatus);

	public String selectOrderObjectSnById(Long orderObjectId);

	public int updateOrderStatusSuccess(String orderObjectSn);
	
	public int updateStatusBySettlementId(Long settlementId,int status,String settlementNo,String companyAccount,String managerAccount);

	public int updateOrderInfoCompanyAndJobNoById(long orderInfoId, Integer companyId, String jobNo);

	public int updateConfirmTime(long orderInfoId, String confirmTime);

	/** 查询用户某状态下订单数 */
	int selectCountByStatus(Long userId, int i);

}
